package vn.vfriends.vcms.admin.util;

import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author tuan@vfriends.vn
 */
public class VietnameseUtil {
    
    private static final String[] specialChars = new String[]{
        "aAeEoOuUiIdDyY",
        "áàạảãâấầậẩẫăắằặẳẵ",
        "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
        "éèẹẻẽêếềệểễ",
        "ÉÈẸẺẼÊẾỀỆỂỄ",
        "óòọỏõôốồộổỗơớờợởỡ",
        "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
        "úùụủũưứừựửữ",
        "ÚÙỤỦŨƯỨỪỰỬỮ",
        "íìịỉĩ",
        "ÍÌỊỈĨ",
        "đ",
        "Đ",
        "ýỳỵỷỹ",
        "ÝỲỴỶỸ"
    };
    
    public static String replaceUnicode(String text) {
        if(StringUtils.isEmpty(text)) {
            return text;
        }
        
        for (int i = 1; i < specialChars.length; i++) {
            for (int j = 0; j < specialChars[i].length(); j++) {
                text = text.replace(specialChars[i].charAt(j), specialChars[0].charAt(i - 1));
            }
        }
        return text;
    }
}
